﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace HospitalSystem
{
    public partial class ReportEachService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);

                List<string> CIDList = new List<string>();

                string caseNumber = Request.QueryString["CaseNo"];
                string CID = Request.QueryString["IDStudent"];
                

                SqlCommand cmd = new SqlCommand("select CID from Evaluation where CID = @CID and CaseNo = @CaseNo", scon);
                cmd.Parameters.AddWithValue("@CID", CID);
                cmd.Parameters.AddWithValue("@CaseNo", caseNumber);
                SqlDataReader reader1 = cmd.ExecuteReader();
                while (reader1.Read() != false)
                {
                    CIDList.Add(reader1["CID"].ToString());
                }
                reader1.Close();
                scon.Close();
                //
                if (CIDList.Count == 1)
                {
                    BindGridview(caseNumber, CID);
                }
                else
                {
                    MessageBox("Error!!!!!!!");
                }
            }
        }


        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }

        private void BindGridview(string caseNumber, string CID)
        {
            DataTable tempPSNumber = new DataTable();
            DataTable temp = new DataTable();
            DataTable showTable = new DataTable();

            tempPSNumber.Columns.Add("PSNumber");
            temp.Columns.Add("ACTCode");

            showTable.Columns.Add("ServiceName");
            showTable.Columns.Add("Money");


            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);
            scon.Open();
            SqlCommand cmd5 = new SqlCommand("select PSNumber from ServiceProvisionVsPerson where CID = @CID and CaseNo = @CaseNo", scon);
            cmd5.Parameters.AddWithValue("@CID", CID);
            cmd5.Parameters.AddWithValue("@CaseNo", caseNumber);
            SqlDataReader reader5 = cmd5.ExecuteReader();
            while (reader5.Read() != false)
            {
                tempPSNumber.Rows.Add(reader5["PSNumber"]);
            }
            reader5.Close();
            for (int i = 0; i < tempPSNumber.Rows.Count; i++)
            {

                SqlCommand cmd6 = new SqlCommand("select ServiceProvisionDetails.ACTCode from ServiceProvision inner join ServiceProvisionDetails on ServiceProvision.PSNumber = ServiceProvisionDetails.PSNumber where ServiceProvision.PSNumber = @PSNumber", scon);
                cmd6.Parameters.AddWithValue("@PSNumber", tempPSNumber.Rows[i]["PSNumber"]);
                SqlDataReader reader6 = cmd6.ExecuteReader();
                while (reader6.Read() != false)
                {
                    temp.Rows.Add(reader6["ACTCode"]);
                }
                reader6.Close();
            }

            //Temp Table Record All Activity 
        }

    }
}